package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.ImpressionList;

public class ImpressionListParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {
		ImpressionList impressionList = new ImpressionList();

		ListModelParser.parseListModel(impressionList, jsonObject);
		JSONObject data = jsonObject.optJSONObject("data");
		JSONArray array = data.optJSONArray("items");
		impressionList.items = new ArrayList<ImpressionList.Impression>();
		for (int i = 0; array != null && i < array.length(); i++) {
			JSONObject object = array.optJSONObject(i);
			if (object != null) {
				ImpressionList.Impression imp = new ImpressionList.Impression();
				imp.content = object.optString("content", "");
				imp.datetime = object.optString("datetime", "");
				imp.id = object.optString("id", "");
				imp.username = object.optString("username", "");
				impressionList.items.add(imp);
			}
		}

		return impressionList;

	}
}
